package com.yociyy.common.core.msg;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * 响应信息公共对象
 *
 * @author YoCiyy
 * @date 2019-12-12
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class R<T> implements Serializable {
	private static final long serialVersionUID = 1L;

	private T data;

	private String msg;

	private int code;

	public static <T> R<T> success() { return new R<T>(null, null, 0); }

	public static <T> R<T> success(T data) { return new R<T>(data, null, 0); }

	public static <T> R<T> success(String msg) { return new R<T>(null, msg, 0); }

	public static <T> R<T> success(T data, String msg) { return new R<T>(data, msg, 0); }

	public static <T> R<T> error() { return new R<T>(null, null, 1); }

	public static <T> R<T> error(T data) { return new R<T>(data, null, 1); }

	public static <T> R<T> error(String msg) { return new R<T>(null, msg, 1); }

	public static <T> R<T> error(T data, String msg) { return new R<T>(data, msg, 1); }
}
